<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>注册</title>
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
    <meta content="black" name="apple-mobile-web-app-status-bar-style" />
    <meta content="telephone=yes" name="format-detection" />
    <link href="css/index.css" rel="stylesheet" type="text/css">
    <link href="css/registered.css" rel="stylesheet" type="text/css">
    <script src="js/jquery-1.8.3.min.js"></script>
    <script src="js/layer/layer.js"></script>
    <script src="js/jquery.md5.js"></script>
</head>
<body>
<div class="viewport">
    <div class="header">
        <div class="header-1"><a href="Login.html"><img src="images/u15.png"></a></div>
        <div class="header-2">注册个人新用户</div>
        <div class="header-3"><div class="header-3-1"></div> </div>
    </div>
    <div class="blank"></div>
    <div class="content">
        <div class="content-1"><!--<a href="registered-3.html"><span>企业用户注册</span><img src="images/u33.png"></a>--> </div>
        <div class="content-2"><input type="text" placeholder="请输入手机号" id="username" maxlength="15px;"></div>
        <div class="content-3"><input type="text" placeholder="请输入验证码" id="code" maxlength="6px;"><span id="yzm" class="yam" onclick="document.getElementById('yzm').innerHTML = yzm();"></span> </div>
        <div class="content-4"><a href="javascript:void(0)" onclick="document.getElementById('yzm').innerHTML = yzm();">看不清楚，换一张</a> </div>
        <div class="content-7"><input type="button" value="确认申请" id="submit"></div>
    </div>
</div>
</body>
</html>
<script type="text/javascript">
    var fss=function(){
        var arr = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','0','1','2','3','4','5','6','7','8','9'];
        var str = '';
        for(var i = 0 ; i < 4 ; i ++ )
            str += ''+arr[Math.floor(Math.random() * arr.length)];
        $("#yzm").text(str);
    };
    $(function(){
        fss()
    });
    function yzm(){
        var arr = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','0','1','2','3','4','5','6','7','8','9'];
        var str = '';
        for(var i = 0 ; i < 4 ; i ++ )
            str += ''+arr[Math.floor(Math.random() * arr.length)];
        return str;
    }
    $(function(){
        $("#submit").click(function(){
            var username=$("#username").val();
            var code=$("#code").val().toUpperCase();
            var patrn =/^1[3,5,8]\d{9}$/;
            var yzm=$("#yzm").text();
            if(username==""){
                layer.msg("请输入手机号",{shadeClose:true,shade:0.1,time:2000})
            }
            else if(!patrn.test(username)){
                layer.msg("请输入正确格式手机号",{shadeClose:true,shade:0.1,time:2000})
            }
            else if(code==""){
                layer.msg("请输入验证码",{shadeClose:true,shade:0.1,time:2000})
            }
            else if(code.length<4){
                layer.msg("验证码少于4位字符",{shadeClose:true,shade:0.1,time:2000})
            }
            else if(code.length>4){
                layer.msg("验证码大于于4位字符",{shadeClose:true,shade:0.1,time:2000})
            }
            else if(code!=yzm){
                layer.msg("验证码错误",{shadeClose:true,shade:0.1,time:2000});
                fss()
            }
            else{
                //15207172332  123
                //http://localhost:8080/nsy-web/api/card/centerService?serviceCode=5001A02&sign=5f9e152adc8953f31487140d6c0982a590b2ca10&timestamp=20160627111123&nonce=123456789&editUser=zhangsan&editTime=20160627111127&device=iphone&ipaddr=192.168.1.111&mac=fa-ef-2d-34-fd&registerNum=15207172332&registerType=p&realyName=%E9%83%91%E7%A7%8B%E7%94%9F&registerCompany=0&pwd=123
                var index =layer.load(2,{content:"loading..."});
                $.ajax({
                    type:"post",
                    url:"http://http://www.accecard.com/nsy-web/api/card/centerService",
                    data:{
                        serviceCode:"5001A01",
                        sign:"5f9e152adc8953f31487140d6c0982a590b2ca10",
                        timestamp:"20160627111123",
                        nonce:"123456789",
                        editUser:"zhangsan",
                        editTime:"20160627111127",
                        ipaddr:"129.12.10.232",
                        device:"iphone",
                        mac:"fa-ef-2d-34-fd",
                        registerNum:username,
                        registerType:"p"

                    },
                    success:function(data){
                        var a = eval("("+data+")");
                        if(a.returnCode=="200"){
                            layer.close(index);
                            window.location = "registered-2.html?"+document.getElementById("username").value;
                        }
                        else if(a.returnCode=="20020"){
                            layer.close(index);
                            layer.msg("账号已存在",{shadeClose:true,shade:0.1,time:2000});
                        }
                        else{
                            layer.close(index);
                            layer.msg("注册失败",{shadeClose:true,shade:0.1,time:2000});
                        }
                    },
                    error: function(XMLHttpRequest, textStatus, errorThrown) {
                        alert("注册错误")
                    }
                });
            }
        })
    });

</script>
